﻿/******************************************************************
** 文 件 名: Bu_DocReceive_Temp_DAL.cs
** Copyright (c) 2010-2012 Honestysoft (GuangZhou) Co.,LTD
** 创 建 人: 此代码由生成器自动生成
** 创建日期: 2012-4-14 15:23:06
** 描    述: 实现公共部分的数据访问封装，提供资料接收表回执--首次新增的数据访问类
** 版    本: 2.0.0.0
** 修改描述:
** 修 改 人:
** 修改日期:
******************************************************************/
using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Text;
using Honestysoft.BaseObject;
using Honestysoft.Financing.Model;

namespace Honestysoft.Financing.DataAccess
{
	/// <summary>
    /// Bu_DocReceive_Temp数据访问类
    /// </summary>
	public partial class Bu_DocReceive_Temp_DAL : BaseDataAccess<Bu_DocReceive_Temp>
    {		
		/// <summary>
        /// 构造函数，使用指定的连接字符串
        /// </summary>
        /// <param name="connectionStringName">连接字符串名称</param>
        public Bu_DocReceive_Temp_DAL(string connectionStringName)
            : base(connectionStringName)
        {

        }

        public void ToDatabase(string recID,string userID)
        {
            DbCommand command = GetStoredProcCommand("Proc_ToDatabase");
            DbParameter pID = CreateParameter("id");
            pID.DbType = DbType.String;
            pID.Value = recID;
            DbParameter pUserID = CreateParameter("UserID");
            pUserID.DbType = DbType.String;
            pUserID.Value = userID;
            //DbParameter pProjectID = CreateParameter("ProjectID");
            //pProjectID.DbType = DbType.String;
            //pProjectID.Direction = ParameterDirection.Output;
            //DbParameter pContractID = CreateParameter("ContractID");
            //pContractID.DbType = DbType.String;
            //pContractID.Direction = ParameterDirection.Output;
            command.Parameters.Add(pID);
            command.Parameters.Add(pUserID);
            //command.Parameters.Add(pProjectID);
            //command.Parameters.Add(pContractID);
            ExecuteNonQuery(command);
            //projectId = pProjectID.Value.ToString();
            //contractId = pContractID.Value.ToString();
        }

        public int UpdateProjectInfo(BD_Project project, DbTransaction transaction)
        {
            DbParameter pProjectID = CreateParameter("ProjectID");
            pProjectID.DbType = DbType.String;
            pProjectID.Value = project.ID;
            string sql = string.Format(@"Update A Set A.ProjectCode=B.Code,A.ProjectName=B.Name,A.OwnerName=C.CompName
                    From Bu_DocReceive_Temp A Inner Join BD_Project B On A.ProjectID=B.ID Inner Join Org_Company C On B.Owner=C.ID
                    Where A.ProjectID={0}",
                        pProjectID.ParameterName);
            DbCommand command = GetDbCommand(sql);
            command.Parameters.Add(pProjectID);
            return ExecuteNonQuery(command, transaction);
        }

        public int UpdateContractInfo(BD_Contract contract, DbTransaction transaction)
        {
            DbParameter pContractID = CreateParameter("ContractID");
            pContractID.DbType = DbType.String;
            pContractID.Value = contract.ID;
            string sql = string.Format(@"
                Update A Set A.ContractCode=B.Code,A.ContractName=B.Name,A.ContractorName=C.CompName
                From Bu_DocReceive_Temp A Inner Join BD_Contract B On A.ContractID=B.ID
                Inner Join Org_Company C ON B.Contractor=C.ID
                Where A.ContractID={0}",
                        pContractID.ParameterName);
            DbCommand command = GetDbCommand(sql);
            command.Parameters.Add(pContractID);
            return ExecuteNonQuery(command, transaction);
        }
    }
}
